package b_TreeSet;

import java.util.Comparator;
import java.util.TreeMap;

/**
 * @author Cheng-02
 * @version V1.0
 * @Package b_TreeSet
 * @date 2024/4/11 下午7:07
 */
public class Test02 {
    public static void main(String[] args) {
        TreeMap<String, Integer> treeMap = new TreeMap<>();
        treeMap.put("张三", 18);
        treeMap.put("王五", 30);
        treeMap.put("李四", 21);

        System.out.println(treeMap);
        TreeMap<Person,String> treemap = new TreeMap<>(new Comparator<Person>() {
            @Override
            public int compare(Person o1, Person o2) {
                return  o1.getAge()-o2.getAge();
            }
        });

        treemap.put(new Person("张三", 18),"北京");
        treemap.put(new Person("李四", 21),"北京");
        treemap.put(new Person("王五", 17),"北京");
        System.out.println(treemap);

    }
}
